<template>
  <div class="mod-config">
      <div class="avue-crud" v-if="dataList.length">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column label="操作" width="220">
            <template slot-scope="scope">
              <el-button type="text" size="small" icon="el-icon-collection" @click="returnVisitInfo(scope.row.id)">详情</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="customerCard" label="会员卡号"></el-table-column>
          <el-table-column prop="name" label="姓名"></el-table-column>
          <el-table-column prop="saleBillId" label="配镜单号">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="feedbackDate" label="回访时间"></el-table-column>
          <el-table-column prop="phone1" label="联系电话"></el-table-column>
          <el-table-column prop="createTime" label="配镜时间"></el-table-column>
          </el-table>
      </div>
      <div class="avue-crud__pagination" v-if="dataList.length">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          background
          layout="total, sizes, prev, pager, next"
        ></el-pagination>
      </div>
      <!-- 弹窗，回访详情信息 -->
      <visit-detail v-if="feedbackVisible" ref="backDetail" @refreshDataList="getDataList"></visit-detail>
      <!-- 点击配镜单号跳转到配镜详情页 -->
      <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
import { getFeedbackInfo } from "@/api/eims/customer.js";
import { mapGetters } from "vuex";
import VisitDetail from '../customer-feedback/detail'
import OrderInfo from '@/views/eims/optician/glassesinfo/detail'

export default {
  data() {
    return {
      infoVisible: false,
      dataList: [],
      searchShow: true,
      pageIndex: 1,
      pageSize: 100,
      totalPage: 0,
      dataListLoading: false,
      feedbackVisible: false
    };
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  components: {
    VisitDetail,
    OrderInfo
  },
  methods: {
    // 初始化数据
    init(customerId,customerCard) {
      this.customerId = customerId
      this.customerCard = customerCard
      this.$nextTick(() => {
        this.getDataList()
      })
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }
        let params2 = {
          customerId : this.customerId,
          customerCard: this.customerCard}
      getFeedbackInfo(Object.assign(params1, params2)).then(response => {
        if(response.data.code == '0'){
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        }else{
          this.$message.error(response.data.msg)
        }
        this.dataListLoading = false
      });
      
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    //查看详情
    returnVisitInfo(id){
      this.feedbackVisible = true
      this.$nextTick(() => { this.$refs.backDetail.init(id) })
    },
    //  查看配镜单详情
    checkDetailByOrder(order){
      this.infoVisible = true;
      this.$nextTick(() => {
        this.$refs.infoDialog.init('',order,'配镜单详情');
      });
    },
  }
};
</script>
